package com.cws4cloud.cws.sdAdmin.biz.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cws4cloud.cws.common.core.util.R;
import com.cws4cloud.cws.common.log.annotation.SysLog;
import com.cws4cloud.cws.sdAdmin.api.entity.UserInfo;
import com.cws4cloud.cws.sdAdmin.api.service.UserInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 用户信息记录表
 *
 * @author zhulj
 * @date 2021-05-10 23:06:25
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/userinfo")
@Api(value = "userinfo", tags = "用户信息记录表管理")
public class UserInfoController {

    private final  UserInfoService userInfoService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param userInfo 用户信息记录表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('sdAdmin_userinfo_get')" )
    public R getUserInfoPage(Page page, UserInfo userInfo) {
        return R.ok(userInfoService.page(page, Wrappers.query(userInfo)));
    }


    /**
     * 通过id查询用户信息记录表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('sdAdmin_userinfo_get')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(userInfoService.getById(id));
    }

    /**
     * 新增用户信息记录表
     * @param userInfo 用户信息记录表
     * @return R
     */
    @ApiOperation(value = "新增用户信息记录表", notes = "新增用户信息记录表")
    @SysLog("新增用户信息记录表")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('sdAdmin_userinfo_add')" )
    public R save(@RequestBody UserInfo userInfo) {
        return R.ok(userInfoService.save(userInfo));
    }

    /**
     * 修改用户信息记录表
     * @param userInfo 用户信息记录表
     * @return R
     */
    @ApiOperation(value = "修改用户信息记录表", notes = "修改用户信息记录表")
    @SysLog("修改用户信息记录表")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('sdAdmin_userinfo_edit')" )
    public R updateById(@RequestBody UserInfo userInfo) {
        return R.ok(userInfoService.updateById(userInfo));
    }

    /**
     * 通过id删除用户信息记录表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除用户信息记录表", notes = "通过id删除用户信息记录表")
    @SysLog("通过id删除用户信息记录表")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('sdAdmin_userinfo_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(userInfoService.removeById(id));
    }

}
